﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
using ObTookit.Model;

namespace ObTookit.Init
{
    public class SentenceDA
    {
        #region SELECT
        internal SQLSentenceEO SelectByName(string sqlName)
        {
            return SelectByName(sqlName, 1);
        }
        internal SQLSentenceEO SelectByName(string sqlName, int status)
        {
            SQLSentenceEO snt = new SQLSentenceEO();
            string sql = "SELECT * FROM SqlSentence WHERE Status = " + status + " AND SqlName='" + sqlName + "'";
            SQLiteCommand cmd = SQLiteHelper.CreateCommand(sql);
            DataSet ds = SQLiteHelper.ExecuteDataSet(cmd);
            DataTable dt = ds.Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                DataModelHandler<SQLSentenceEO> dmh = new DataModelHandler<SQLSentenceEO>();
                snt = dmh.FillModel(dt.Rows[0]);
            }
            return snt;
        }

        internal List<SQLSentenceEO> SelectList(int status)
        {
            List<SQLSentenceEO> sss = new List<SQLSentenceEO>();
            string sql = "SELECT * FROM SqlSentence WHERE Status = " + status;
            SQLiteCommand cmd = SQLiteHelper.CreateCommand(sql);
            DataSet ds = SQLiteHelper.ExecuteDataSet(cmd);
            DataTable dt = ds.Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                DataModelHandler<SQLSentenceEO> dmh = new DataModelHandler<SQLSentenceEO>();
                sss = dmh.FillModel(dt);
            }
            return sss;
        }
        #endregion 
    }
}
